﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RandomSearch.Plugins.AssemblySearch;
using RandomSearch.PluginsCommon;

namespace UnitTests {
    [TestClass]
    public class AssemblySearchConcept {
        
        [TestMethod]
        [DeploymentItem("RandomSearch.Plugins.AssemblySearch.dll")]
        public void AssemblyTestFail() {
            const string classToSearch = "BaseSearchPlugin";
            var plugin = new AssemblySearch();
            var searchOptions = new SearchOptions
                                    {
                                        IncludeSubfolders = false, 
                                        PathToRootFolder = Environment.CurrentDirectory,
                                        PluginId = plugin.PluginId,
                                        Settings = new Dictionary<string, string>
                                                       {
                                                           { "AssemblySearch_Class", classToSearch },
                                                           { "AssemblySearch_Case", "False" }
                                                       }
                                    };
            var res = plugin.Search(searchOptions).ToList();
            Assert.AreEqual(0,res.Count);
        }


        [TestMethod]
        [DeploymentItem("RandomSearch.Plugins.AssemblySearch.dll")]
        public void AssemblyTest() {
            const string classToSearch = "ISearchPlugin";
            var plugin = new AssemblySearch();
            var searchOptions = new SearchOptions {
                IncludeSubfolders = false,
                PathToRootFolder = Environment.CurrentDirectory,
                PluginId = plugin.PluginId,
                Settings = new Dictionary<string, string>
                                                       {
                                                           { "AssemblySearch_Class", classToSearch },
                                                           { "AssemblySearch_Case", "False" }
                                                       }
            };
            var res = plugin.Search(searchOptions).ToList();

            Assert.AreEqual(2, res.Count);
            Assert.AreEqual("RandomSearch.Plugins.DefaultSearch.dll", new FileInfo(res[1].File).Name);
            Assert.AreEqual("RandomSearch.Plugins.AssemblySearch.dll", new FileInfo(res[0].File).Name);
        }
    }
}